﻿@{
    ViewBag.Title = "mpedit";
}
@section scripts
{
    <link href="~/Scripts/miniui/themes/default/large-mode.css" rel="stylesheet" type="text/css" />       
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <style>
        body {
            font-size:10pt !important;
        }
    </style>
}
<form id="form1">

            <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                        </td>
                    </tr>
                </table> 
            </div> 

            <table style="width:660px;">
                <tr>
                    <td bgcolor="#D7FFFF">会员信息：</td>
                </tr>
            </table>

            <table  style="width:660px;">
                 <tr>
                    <td width ="80px" align="right">会员卡号： </td>
                    <td width ="200px">
                        <input id="FNumber" class="mini-buttonedit"style="width:200px; top: 0px; left: 0px;" 
                            onbuttonclick="onButtonEdit" name="FNumber" onvaluechanged ="GetMemberID" textName="b" align="left"/>
                     </td>
                    <td width ="80px" align="right">会员姓名：</td>
                    <td width ="200px">
                       <input name="FName" class="mini-textbox" style="width:200px;" readonly="readonly"/></td>
                    <td align="center">      
                        <a class="mini-button" onclick="GetMemberID" style="width:70px;margin-right:10px;">读卡</a>
                    </td>
                </tr>
                <tr>
                    <td width ="80px" align="right">
                        会员分类：</td>
                    <td width ="190px">
                        <input id="className" name="className" class="mini-textbox" enabled="false" style="width:200px;" />
                    </td>
                    <td  align="right">
                        当前余额：</td>
                    <td >
                        <input name="FCurrentAmount" class="mini-spinner" minValue="-99999999" maxValue="99999999" 
                            changeOnMousewheel ="false" showbutton="false" increment ="0" showbutton="false" enabled="false" style="width:200px;" required="true"/></td>
                </tr>
                <tr>
                    <td align="right">
                        当前积分：</td>
                    <td >
                        <input name="FPoint" class="mini-spinner" minValue="-9999999" maxValue="99999999" 
                            changeOnMousewheel ="false" showbutton="false" increment ="0" showbutton="false" enabled="false" style="width:200px;" required="true"/></td>
                    <td align="right">折扣：</td>
                    <td >
                       <input name="FDiscount" class="mini-spinner" minValue="0" maxValue="99999999" enabled="false" changeOnMousewheel ="false" increment ="0" showbutton="false" style="width:200px;"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">联系电话：</td>
                    <td >
                        <input name="FPhone" class="mini-textbox" style="width:200px;" enabled="false"  maxlength="50" />
                    </td>
                    <td align="right">联系地址：</td>
                    <td >
                        <input name="FAddress" class="mini-textbox" style="width:200px;" enabled="false"  maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td align="right">备注：</td>
                    <td >
                        <input name="FRemark" class="mini-textbox" style="width:200px;"  maxlength="100" enabled="false"/>
                    </td>
                    <td align="right">充值单号：</td>
                    <td >
                        <input name="FBillNo" class="mini-textbox" style="width:200px;" enabled="false"  maxlength="100" />
                    </td>
                </tr>
        </table>

            <table style="width:660px;">
                <tr>
                    <td bgcolor="#D7FFFF"><span id="titles">会员充值：</span></td>
                </tr>
            </table>

            <table style="width:660px;">
                <tr>
                    <td width ="80px" align="right"><span id="payAmount">充值金额：</span></td>
                    <td width ="200px">
                        <input name="FAmount" class="mini-spinner" value="0" minValue="-1000000" maxValue="99999999"
                        changeOnMousewheel ="false" showbutton="false" style="width:200px;" selectOnFocus="true"/>
                    </td>
                    <td width ="80px" align="right"><span id="payPoint">赠送金额：</span></td>
                    <td >
                        <input name="FSetAmount" class="mini-spinner" value="0" minValue="0" maxValue="1000000" 
                        changeOnMousewheel ="false" showbutton="false" style="width:200px;"  selectOnFocus="true"/>

                    </td>
                    <td align="center">  <a class="mini-button" id="PayBtn" name="PayBtn" onclick="SaveInfo" style="width:70px;margin-right:10px;">充值</a>
                    </td>
                </tr>
                <tr>
                    <td align="right">门店名称：</td>
                    <td>
                        @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")
                    </td>
                    <td align="right">
                        付款方式：
                    </td>
                    <td>
                        @Html.Partial("~/Views/Modular/LookupPayment.cshtml")
                    </td>
                </tr>
                <tr>
                    <td align="right">导购员：</td>
                    <td>
                        @Html.Partial("~/Views/Modular/LookupGuider.cshtml")
                    </td>
                    <td align="right">备注：</td>
                    <td>
                        <input name="FPayRemark" class="mini-textbox" style="width:200px;"  maxlength="100"/>
                    </td>
                </tr>
            </table>

           
    <input name="FItemID" class="mini-hidden" />
    <input name="Type" value="@ViewBag.Type" class="mini-hidden" />
    <input name="BillNo" value="@ViewBag.BillNo" class="mini-hidden" />
    <input name="BillID" value="@ViewBag.BillID" class="mini-hidden" />
    </form>
<script>
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }

    $(function () {
        $.post("GetItem", { json: "StockInfo", mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var mdata = mini.decode(data);
            mini.getbyName("FStockID").setValue(mdata.FItemID);
            mini.getbyName("FStockID").setText(mdata.FNumber);
            mini.getbyName("FStockName").setValue(mdata.FName);
        });
        $.post("GetItem", { json: "PayInfo", mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var mdata = mini.decode(data);
            mini.getbyName("FPayID").setValue(mdata.FItemID);
            mini.getbyName("FPayID").setText(mdata.FNumber);
            mini.getbyName("FPayName").setValue(mdata.FName);
        });
        if (GetQueryString("type") == "1") {
            $("#titles").html("会员积分");
            $("#payAmount").html("加减积分");
            $("#payPoint").html("赠送积分");
        }
        GetBillNo();
    });

    function GetMemberID() {
        var FNumber = mini.getbyName("FNumber").getText();
        var FValue = mini.getbyName("FNumber").getValue();
        if (FNumber == FValue) FValue = "0";
        $.post("GetMembers", { json: "[{'FItemID':'" + FValue + "','FNumber':'" + FNumber + "', 'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.data.length > 0) {                
                mini.getbyName("FNumber").setValue(mdata.data[0].FItemID);
                mini.getbyName("FNumber").setText(mdata.data[0].FNumber);
                mini.getbyName("className").setValue(mdata.data[0].className);
                mini.getbyName("FName").setValue(mdata.data[0].FName);
                mini.getbyName("FRemark").setValue(mdata.data[0].FRemark);
                mini.getbyName("FCurrentAmount").setValue(mdata.data[0].FAmount.toFixed(2));
                mini.getbyName("FPoint").setValue(mdata.data[0].FPoint);
                mini.getbyName("FPhone").setValue(mdata.data[0].FPhone);
                mini.getbyName("FAddress").setValue(mdata.data[0].FAddress);
                mini.getbyName("FDiscount").setValue(mdata.data[0].FDiscount);
                if (!mdata.data[0].FAmountFlag)
                    isEnabled(false);
                else
                    isEnabled(true);
            }
        });
    }

    function isEnabled(Enabled) {
        mini.getbyName("FAmount").setEnabled(Enabled); 
        mini.getbyName("FSetAmount").setEnabled(Enabled); 
        mini.getbyName("PayBtn").setEnabled(Enabled);
        mini.getbyName("FStockID").setEnabled(Enabled);
        mini.getbyName("FStockName").setEnabled(Enabled);
        mini.getbyName("FPayID").setEnabled(Enabled);
        mini.getbyName("FPayName").setEnabled(Enabled);
        mini.getbyName("FGuiderNumber").setEnabled(Enabled);
        mini.getbyName("FGuiderName").setEnabled(Enabled);
    }

    function NewInfo() {
        mini.getbyName("FNumber").setText('');
        mini.getbyName("FNumber").setValue('');
        mini.getbyName("className").setValue('');
        mini.getbyName("FName").setValue('');
        mini.getbyName("FRemark").setValue('');
        mini.getbyName("FAmount").setValue(0);
        mini.getbyName("FSetAmount").setValue(0);
        mini.getbyName("FCurrentAmount").setValue(0);
        mini.getbyName("FPoint").setValue(0);
        mini.getbyName("FPhone").setValue('');
        mini.getbyName("FAddress").setValue('');
        mini.getbyName("FPayRemark").setValue('');
        mini.getbyName("FDiscount").setValue(1);
    }

    function onButtonEdit() {
        mini.open({
            url: "../GetItem/index",
            title: "会员选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "Member", sSearchKey: "" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action.length > 0) {
                    mini.getbyName("FNumber").setText(action[0].FNumber);
                    mini.getbyName("FNumber").setValue(action[0].FItemID);
                    GetMemberID(action.FNumber);
                    mini.getbyName("FAmount").focus();
                }
            }
        });
    }

    function SaveInfo() {
        if (mini.getbyName("FNumber").getValue() == '') {
            mini.alert("未选择会员");
            return;
        }
        mini.getbyName("PayBtn").setEnabled(false);
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;
        var data = form.getData();

        if (data.FAmount == 0 && data.FSetAmount == 0) {
            mini.alert('未输入充值金额');
            mini.getbyName("PayBtn").setEnabled(true);
            return;
        }
        if (data.FStockID == '' && data.FStockID!=0) {
            mini.alert('未选择门店');
            mini.getbyName("PayBtn").setEnabled(true);
            return;
        }
        var json = mini.encode(data);
        $.post("SavePayInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status >= 1) {
                GetBillNo();
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                GetBillNo();
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("PayBtn").setEnabled(true);
        });
    }

    function GetBillNo() {
        var Json = '[{"type":"' + mini.getbyName("Type").getValue() + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        $.post("GetMemberPayBillNo", { json: Json }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.BillOrder.length > 0) {
                mini.getbyName("BillNo").setValue(mdata.BillOrder[0].FBillNo);
                mini.getbyName("BillID").setValue(mdata.BillOrder[0].FEntryID);
                mini.getbyName("FBillNo").setValue(mdata.BillOrder[0].FBillNo);
            }
        });

    }

    function FormShown() { mini.parse();}
</script>

